package gameObjects;

import com.jme.image.Texture;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Quad;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;

public class RandomQuad {
	public static RandomQuad randomQuad;
	public static RandomQuad getInstance()
	{
		if(randomQuad==null)
			randomQuad=new RandomQuad();
		return randomQuad;
	}
	
	public Node create()
    {
    	Texture tex = TextureManager.loadTexture(
			  		"src/textures/magenta_color.jpg",
			  		Texture.MinificationFilter.Trilinear,
			  		Texture.MagnificationFilter.Bilinear);
    	TextureState ts_quad = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
  		ts_quad.setEnabled(true);
  		ts_quad.setTexture(tex);
    	
    	Node quads = new Node();
    	
    	for (int i=0;i<32;i++)
    	{
    		for (int k=0;k<32;k++)
    		{
    			int draw = (int) (Math.random() *100);
    			if (draw>85)
    			{
    				Vector3f axis = Vector3f.UNIT_X;
    				float angle = (3.14f/2);

    				Quad quad = new Quad("quad", 3.8f, 3.8f);
    					 quad.setColorBuffer(null);
    					 quad.setDefaultColor(new ColorRGBA(1f,0,1f,0.5f));
    				     quad.setLocalTranslation(i*4, 25, k*4);
    				     quad.getLocalRotation().fromAngleAxis(angle, axis);
    				     quad.setCastsShadows(true);
    				     quad.setRenderState(ts_quad);
    				quads.attachChild(quad);

    			}
    		}
    	}
    	return quads;
    }
}
